package p3as.cliente;

import java.awt.Graphics;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Renderer extends Thread{
    
    private Scene scene;
    private JDoubleBufferedCanvas jDoubleBufferedCanvas;
    private Graphics g;
    private Principal principal;

    public Renderer(Scene scene, Principal principal) {
        this.scene = scene;
        this.principal = principal;
        jDoubleBufferedCanvas = principal.getCanvas();
    }
    
    @Override
    public void run(){
        g = jDoubleBufferedCanvas.getImage().getGraphics();
        while(true){
            g.clearRect(0, 0, 500, 500);
            scene.render(g);
            
            principal.repaint();
            try {
                Thread.sleep(5);
            } catch (InterruptedException ex) {
                Logger.getLogger(Renderer.class.getName()).log(Level.SEVERE, null, ex);
            }
                   
        }
    }
    
    void setScene(Scene auxScene) {
        synchronized(auxScene){
            this.scene = auxScene;
        }
    }
}
